package cn.ekuma.epos.datalogic.local.dao;

import java.util.Date;

import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import cn.ekuma.epos.datalogic.local.AbstractBaseDAO;
import cn.ekuma.epos.db.table.pda.I_LocalHistory;
import cn.ekuma.epos.db.table.pda.Table;

import com.openbravo.bean.pda.LocalHistory;

public class LocalHistoryDAO extends AbstractBaseDAO<LocalHistory>{

	public LocalHistoryDAO(SQLiteOpenHelper db) {
		super(db);
	}

	public static void onCreate(SQLiteDatabase sqLiteDatabase) {
	    sqLiteDatabase.execSQL(
	    		"CREATE TABLE LOCAL_HISTORY("+
                 "ID VARCHAR(255) NOT NULL,"+
                 "LOCAL_MACHINE_NAME VARCHAR(255) NOT NULL,"+
                 "CREATEDATE TIMESTAMP,"+
                 "CSV_VALUE TEXT,"+
                 "MEMO1 VARCHAR(1023),"+
                 "CSV_MORE TEXT,"+
                 "PRIMARY KEY (ID)"+
                 ");");
  }
	
	@Override
	public String getKeyColumn() {
		return ID;
	}

	@Override
	public LocalHistory readValues(Cursor c, LocalHistory obj) {
		if(obj==null)
			obj=new LocalHistory();
		obj.setId(c.getString(0));
		obj.setLocalMachineName(c.getString(1));
		obj.setCreateDate(new Date(c.getLong(2)));
		obj.setCsvValue(c.getString(3));
		obj.setMemo(c.getString(4));
		obj.setCsvMore(c.getString(5));
		return obj;
	}

	@Override
	public String[] getTableColumns() {
		return new String[]{
			I_LocalHistory.ID,
			I_LocalHistory.LOCAL_MACHINE_NAME,
			I_LocalHistory.CREATEDATE,
			I_LocalHistory.CSV_VALUE,
			I_LocalHistory.MEMO,
			I_LocalHistory.CSV_MORE
		};
	}

	@Override
	public ContentValues createContentValues(LocalHistory t) {
		ContentValues cValue=new ContentValues();
		cValue.put(I_LocalHistory.ID, t.getId());
		cValue.put(I_LocalHistory.LOCAL_MACHINE_NAME, t.getLocalMachineName());
		cValue.put(I_LocalHistory.CREATEDATE, t.getCreateDate().getTime());
		cValue.put(I_LocalHistory.CSV_VALUE, t.getCsvValue());
		cValue.put(I_LocalHistory.MEMO, t.getMemo());
		cValue.put(I_LocalHistory.CSV_MORE, t.getCsvMore());
		return cValue;
	}

	@Override
	public Class getSuportClass() {
		return LocalHistory.class;
	}

	@Override
	public String getTableName() {
		return Table.LOCAL_HISTORY;
	}
	
	

}
